<%--
  Created by IntelliJ IDEA.
  User: ZhuChunXiao
  Date: 2017/5/22
  Time: 10:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<%--<div id="page-content">--%>
  <%--<div class="row">--%>

    <%--<div class="col-lg-12">--%>
      <%--<div class="panel">--%>
        <%--<div class="panel-heading">--%>
          <%--<h3 class="panel-title">奖惩记录</h3>--%>
        <%--</div>--%>
        <div class="panel-body">
          <div class="form-inline" id="tempWidth">
            <input type="hidden" id="parentId" value="${parentId}">
            <div class="row">
              <div class="col-sm-12 table-toolbar-left">
                <btn id="btn_add_personnelreward" class="btn btn-primary btn-sm">
                  <i class="ti-plus"> </i> 新建奖惩登记表
                </btn>
              </div>
            </div>
          </div>
          <div class="table-responsive" id="ajax_personnelreward_list_row">
            <table id="personnelreward_table"></table>
            <div id="personnelreward_page"></div>
          </div>
        </div>

        <div class="panel-footer">
          <a class="btn btn-default" id="apply-re-common7" href="javascript:void(0)">
            <i class="fa fa-lg fa-mail-reply"></i> 返回视图
          </a>
        </div>
      <%--</div>--%>
    <%--</div>--%>

  <%--</div>--%>
<%--</div>--%>

<script>

  $(function(){
    var tableWidth="${tableWidth}";
//    var tableWidth=$("#tempWidth").width();

    init_grid_personnelreward();
    $("#ajax_personnelreward_list_row").width(tableWidth);
    jQuery("#personnelreward_table").jqGrid('setGridWidth', tableWidth-10);

  });

  function init_grid_personnelreward() {

    __init_jqgrid('personnelreward_table', 'personnelreward_page',
            '<%=path%>/activiti/personnelreward/list',
            ['奖惩类型',"奖惩名称","奖惩时间","操作","id"],
            [
              {name: 'type', index: 'type', width: 40, sortable: false, search: false, formatter: personnelrewardTypeFormat},
              {name: 'name', index: 'name', width: 100, sortable: false, stype: 'text', searchoptions: {sopt: ['cn']}},
              {name: 'date', index: 'date', width: 80, sortable: false, search: false, formatter: dateOnlyFormat},
              {name: 'act', index: 'act', width: 150, fixed: true, sortable: false, search: false, formatter: actFormat},
              {name: 'id', index: 'id', width: 100, key: true, hidden: true, hidedlg: true}
            ],
            true,
            {
              postData: {parentId: $("#parentId").val()}
            }
    );

  }

  function dateOnlyFormat(cellvalue, options, rowObject){
    return cellvalue.split(" ")[0];
  }

  function personnelrewardTypeFormat(cellvalue, options, rowObject){
    if(rowObject.type == 1){
      cellvalue = "奖励";
    } else if(rowObject.type == 2){
      cellvalue = "惩罚";
    }
    return cellvalue;
  }

  function actFormat(cellvalue, options, rowObject){
    var id = rowObject.id;
    cellvalue = '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_personnelreward_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button>';

    return cellvalue;
  }

  function fn_personnelreward_read(id) {
    loadURL('<%=path%>/activiti/personnelreward/read/'+id, $('#bsc-tab-7'));
  }

  $("#btn_add_personnelreward").click(function(){
    loadURL('<%=path%>/activiti/personnelreward/create?parentId='+$("#form_personnelinfo_input #keyId").val(), $('#bsc-tab-7'));
  });

  //返回视图
  $("#apply-re-common7").click(returnToHashUrl);
</script>